import { home } from '../../utils/api/home'
import storage from "@/utils/storage"
export default {
  namespaced: true,
  state: {
    tagsLi: {},
    menuArr: [
      {
        id: "1",
        icon: 'el-icon-s-home',
        menuType: 1,
        menuName: '首页',
        path: '/home/first',
      },
      {
        id: '2',
        menuType: 1,
        icon: 'el-icon-s-custom',
        menuName: '角色管理',
        path: '/home/role',
        children: [
          {
            id: "2-1",
            menuType: 1,
            menuName: '角色列表',
            path: '/home/role/list',
          },
          {
            id: "2-2",
            menuType: 2,
            menuName: '权限设置',
            path: '/home/role/limits',
          },
        ]
      },
      {
        id: '3',
        menuType: 1,
        icon: 'el-icon-s-data',
        menuName: '营销管理',
        path: '/home/market',
        children: [
          {
            id: '3-1',
            menuType: 1,
            menuName: '营销活动',
            path: '/home/market/activity',
          },
          {
            id: '3-1-1',
            menuType: 2,
            menuName: '新增/修改活动',
            path: '/home/market/addActivity',
          },
          {
            id: '3-2',
            menuType: 1,
            menuName: '群组管理',
            path: '/home/market/group',
          },
          {
            id: '3-2-1',
            menuType: 2,
            menuName: '新增/修改群组',
            path: '/home/market/addGroup',
          },
          {
            id: '3-2-2',
            menuType: 2,
            menuName: '群组成员',
            path: '/home/market/member',
          },
          {
            id: '3-2-2-1',
            menuType: 2,
            menuName: '新增/修改群组成员',
            path: '/home/market/addMember',
          },
          {
            id: '3-3',
            menuType: 1,
            menuName: '邮件模板',
            path: '/home/market/mail',
          },
          {
            id: '3-3-1',
            menuType: 2,
            menuName: '新增/修改邮件模板',
            path: '/home/market/addMail',
          },
          {
            id: '3-4',
            menuType: 1,
            menuName: '邮件营销',
            path: '/home/market/emailMark',
          },
          {
            id: '3-4-1',
            menuType: 2,
            menuName: '邮件发送',
            path: '/home/market/addEmailMark',
          },
          {
            id: '3-5',
            menuType: 1,
            menuName: '短信模板',
            path: '/home/market/noteMode',
          },
          {
            id: '3-5-1',
            menuType: 2,
            menuName: '新增/修改短信模板',
            path: '/home/market/addNote',
          },
          {
            id: '3-6',
            menuType: 1,
            menuName: '短信营销',
            path: '/home/market/noteMarke',
          },
          {
            id: '3-6-1',
            menuType: 2,
            menuName: '短信发送',
            path: '/home/market/addNoteMarke',
          },

        ]
      },
       {
        id: '4',
        menuType: 1,
        icon: 'el-icon-s-cooperation',
        menuName: '诊断管理',
        path: '/home/Diagnostic',
        children: [
          {
            id: "4-1",
            menuType: 1,
            menuName: '诊断管理',
            path: '/home/Diagnostic/Diagnostic_home',
          },
          {
            id: "4-2",
            menuType: 1,
            menuName: '诊断报表',
            path: '/home/report/report_home',
          },

        ]
      },
       {
        id: '5',
        menuType: 1,
        icon: 'el-icon-s-order',
        menuName: '药品管理',
        path: '/home/Drug_administration',
        children: [
          {
            id: "5-1",
            menuType: 1,
            menuName: '药品管理',
            path: '/home/Drug_administration',
          },
          {
            id: "5-2",
            menuType: 1,
            menuName: '药品分类',
            path: '/home/classification',
          },
          {
            id: "5-3",
            menuType: 1,
            menuName: '药品库存',
            path: '/home/Drug_inventory',
          },
        ]
      },
      {
        id: '6',
        menuType: 1,
        icon: 'el-icon-s-order',
        menuName: '日程管理',
        path: '/home/Schedule_management',
        children: [
          {
            id: "6-1",
            menuType: 1,
            menuName: '日程管理',
            path: '/home/Schedule_management/Schedule_home',
          },
          {
            id: "6-2",
            menuType: 1,
            menuName: '我的日历',
            path: '/home/calendar/calendar_home',
          },
         
        ]
      },
       {
        id: '7',
        menuType: 1,
        icon: 'el-icon-s-platform',
        menuName: '患者管理',
        path: '/home/patientsManagement',
        children: [
          {
            id: "7-1",
            menuType: 1,
            menuName: '患者管理',
            path: '/home/patientsManagement/patientsManagementHome',
          },
          {
            id: "7-2",
            menuType: 1,
            menuName: '患者跟进',
            path: '/home/patientsFollow',
          },
          {
            id: "7-3",
            menuType: 1,
            menuName: '患者公海',
            path: '/home/patientsHighSeas',
          },
          {
            id: "7-4",
            menuType: 1,
            menuName: '患者报表',
            path: '/home/patientsReport',
          },
         
        ]
      },
       {
        id: '8',
        menuType: 1,
        icon: 'el-icon-s-comment',
        menuName: '邮件管理',
        path: '/home/emailManagement',
        children: [
          {
            id: "8-1",
            menuType: 1,
            menuName: '账号管理',
            path: '/home/accountManagement',
          },
          {
            id: "8-2",
            menuType: 1,
            menuName: '邮件管理',
            path: '/home/emailManagement',
          },
          
        ]
      },
       {
        id: '9',
        menuType: 1,
        icon: 'el-icon-phone',
        menuName: '通讯录',
        path: '/home/addressBook',
        children: [
          {
            id: "9-1",
            menuType: 1,
            menuName: '通讯录',
            path: '/home/addressBook/addressBookHome',
          },
          
        ]
      },
       {
        id: '10',
        menuType: 1,
        icon: 'el-icon-user-solid',
        menuName: '用户管理',
        path: '/home/userViews',
        children: [
          {
            id: "10-1",
            menuType: 1,
            menuName: '部门管理',
            path: '/home/userViews/department',
          },
           {
            id: "10-2",
            menuType: 1,
            menuName: '在线用户',
            path: '/home/userViews/onlineUsers',
          },
           {
            id: "10-3",
            menuType: 1,
            menuName: '职位管理',
            path: '/home/userViews/position',
          },
           {
            id: "10-4",
            menuType: 1,
            menuName: '用户管理',
            path: '/home/userViews/userControl',
          },
        ]
      },
       {
        id: '11',
        menuType: 1,
        icon: 'el-icon-s-management',
        menuName: '供应管理',
        path: '/supplier',
        children: [
          {
            id: "11-1",
            menuType: 1,
            menuName: '供应商管理',
            path: '/supplier',
          },
           {
            id: "11-2",
            menuType: 1,
            menuName: '供应商跟进',
            path: '/trail',
          },
           
        ]
      },
       {
        id: '12',
        menuType: 1,
        icon: 'el-icon-message-solid',
        menuName: '客服管理',
        path: '/airlines',
        children: [
          {
            id: "12-1",
            menuType: 1,
            menuName: '客服管理',
            path: '/airlines',
          },
           {
            id: "12-2",
            menuType: 1,
            menuName: '问题管理',
            path: '/emerson',
          },
            {
            id: "12-3",
            menuType: 1,
            menuName: '客服报表',
            path: '/report',
          },
        ]
      },
       {
        id: '13',
        menuType: 1,
        icon: 'el-icon-s-platform',
        menuName: '系统管理',
        path: '/home/ViewportMenu',
        children: [
          {
            id: "13-1",
            menuType: 1,
            menuName: '菜单管理',
            path: '/home/ViewportMenu/MenuManagement',
          },
           {
            id: "13-2",
            menuType: 1,
            menuName: '类型管理',
            path: '/home/ViewportType/TypeManagement',
          },
            {
            id: "13-3",
            menuType: 1,
            menuName: '状态管理',
            path: '/home/ViewportState/StateManagement',
          },
            {
            id: "13-4",
            menuType: 1,
            menuName: '快递公司',
            path: '/home/ViewportCourier/CourierCompany',
          },
        ]
      },
    ],
    username: storage.getStorage('username') || '',
    tabList: storage.getStorage('tabList') || []
  },
  getters: {
  },
  mutations: {
    addhomeLimits(state, arr) {
      state.menuArr = arr
    },
    addTabs(state, val) {
      state.tagsLi = { ...val };
      if (val.path != '/home/first') {
        let resp = state.tabList.findIndex(item => item.path == val.path)

        if (resp == -1) {
          state.tabList.push(state.tagsLi)
        }
      }
    },
    closeTabs(state, val) {
      let resp = state.tabList.findIndex(item => item.path == val)
      console.log(resp);
      if (resp !== -1) {
        state.tabList.splice(resp, 1)

      }
      //  storage.setStorage('tabList',state.tabList)

    },
    delTabs(state, str) {
      console.log(str);
      if (str == "/home/first") {
        state.tabList.splice(0, state.tabList.length)
      } else {
        state.tabList.forEach((item, index) => {
          if (item.path === str) {
            state.tabList = state.tabList.slice(index, index + 1)
          }
        })
      }

      //  storage.setStorage('tabList',state.tabList)
    }
  },
  actions: {
    async sethomeLimits(commap, obj) {
      return home(obj).then(data => new Promise((resolve, reject) => {
        console.log(data);
      }))
    }
  },
}